#include "ringQueue.hpp"
#include <pthread.h>
#include <unistd.h>
#include <time.h>
using namespace std;
void *productor(void *argv)
{
    ringQueue<int> *rq = static_cast<ringQueue<int> *>(argv);
    while (1)
    {
        int tmp = rand() % 10;
        rq->Push(tmp);
        cout <<PthreadSelf()<< "生产者 Push:" << tmp << endl;
    }
}
void *comsumer(void *argv)
{
    ringQueue<int> *rq = static_cast<ringQueue<int> *>(argv);
    while (1)
    {
        
        int tmp;
        rq->Pop(&tmp);
        cout <<PthreadSelf()<< "消费者 Pop:" << tmp << endl;
    }
}
int main()
{
    srand((unsigned long)time(nullptr) ^ getpid());
    ringQueue<int> *rq = new ringQueue<int>(50);
    pthread_t p[6], c[4];
    for(int i = 0;i<6;i++)pthread_create(p+i, nullptr, productor, rq);
    for(int i = 0;i<4;i++)pthread_create(c+i, nullptr, comsumer, rq);
    for(int i = 0;i<6;i++)pthread_join(p[i], nullptr);
    for(int i = 0;i<4;i++)pthread_join(c[i], nullptr);
}